package com.oasen.learn.usercenter.action.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.Template;

import com.oasen.learn.usercenter.entity.UserMeta;
import com.oasen.learn.usercenter.service.UserMetaService;

@Controller
public class UserMetaController {
	@Autowired
	private UserMetaService userMetaService;
	@Autowired
	private RedisTemplate<String, String> redisTemplate;
	
	@RequestMapping("/")
	public @ResponseBody UserMeta index(Model model){
//		UserMeta userMeta = userMetaService.get();
		UserMeta userMeta = new UserMeta();
		userMeta.setUname("sen");
		model.addAttribute("userMeta", userMeta);
		return userMeta;
	}
	@RequestMapping("/user")
	public String user(Model model){
		
		return "index";
	}
	
	@RequestMapping("setRedis")
	public String setRedis(){
		ValueOperations<String, String> op = redisTemplate.opsForValue();
		op.set("sen","hey girl");
		return "index";
	}
	
	@RequestMapping("getRedis")
	public @ResponseBody String getRedis(){
		String sen = redisTemplate.opsForValue().get("sen");
		return sen;
	}
	
	@RequestMapping("/redis")
	public @ResponseBody List<String> redis(Model model){
		BoundListOperations<String, String> redisList = redisTemplate.boundListOps("list_key");
		List<String> list = redisList.range(0, 1);
		return list;
	}
}
